package product

import (
	"context"
	"group-buy/group_buy/internal/models"

	"group-buy/group_buy/internal/svc"
	"group-buy/group_buy/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetProductDivisionLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetProductDivisionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductDivisionLogic {
	return &GetProductDivisionLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetProductDivisionLogic) GetProductDivision(req *types.GetProductDivisionReq) (resp *types.ProductDivision, err error) {
	m := &models.ProductDivision{ProductId: req.ProductId}

	_, err = l.svcCtx.Engine.Get(m)
	if err != nil {
		return nil, err
	}
	return &types.ProductDivision{
		Id:                 m.Id,
		ProductName:        m.ProductName,
		ProductId:          m.ProductId,
		InviteAmount:       m.InviteAmount,
		InviteParentAmount: m.InviteParentAmount,
		BusinessAmount:     m.BusinessAmount,
		DealerAmount:       m.DealerAmount,
	}, nil
}
